.SFILES    =   crt0.s intr_main.s MultiSioAsm.s
.CFILES    =   main.c loader_main.c sub.c \
               intr_table.c bss.c data.c load_table_src.c \
               MultiBoot.c MultiSio.c Sio32MultiLoad.c
.BINFILES  =   client.bin demo.bin
.OFILES    =   $(.SFILES:.s=.o) $(.CFILES:.c=.o)  $(.BINFILES:.bin=.o)

AGBINC	   =	$(AGBDIR)/include
AGBLIB	   =	$(AGBDIR)/lib

ASFLAGS    =          -I$(AGBINC) -mthumb-interwork
CFLAGS     =   -g -O2 -I$(AGBINC) -mthumb-interwork \
               -nostdlib #-DNDEBUG
LDFLAGS    +=  -Map $(MAPFILE) -nostartfiles \
               -Ttext 0x08000000 -Tbss 0x03000000 \
               -L$(AGBLIB) -lagbsyscall -lisagbprn

DEPENDFILE   =   sio32_multi_load.dep
MAPFILE      =   sio32_multi_load.map
TARGET_ELF   =   sio32_multi_load.elf
TARGET_BIN   =   sio32_multi_load.bin
		
.SUFFIXES: .bin

.bin.o:
	objcopy -v -I binary -O elf32-little $< $@


default:
	@$(MAKE) -f MakefileDemo
	@$(MAKE) -f MakefileClient
	@$(MAKE) $(TARGET_BIN)


$(TARGET_BIN): $(TARGET_ELF)
	objcopy -v -O binary $< $@

$(TARGET_ELF): $(.OFILES) Makefile $(DEPENDFILE)
	@echo > $(MAPFILE)
	$(CC) -g -o $@ $(.OFILES) -Wl,$(LDFLAGS)


.PHONY: all clean depend


all:    clean default

clean:
	@$(MAKE) -f MakefileDemo   clean
	@$(MAKE) -f MakefileClient clean
	-rm $(.OFILES) $(DEPENDFILE) $(MAPFILE) $(TARGET_ELF) $(TARGET_BIN) $(CLIENT_OFILE)

depend:
	@$(MAKE) -f MakefileDemo   depend
	@$(MAKE) -f MakefileClient depend
	$(CC) $(CFLAGS) -M $(.CFILES) > $(DEPENDFILE)

$(DEPENDFILE): 
	$(CC) $(CFLAGS) -M $(.CFILES) > $(DEPENDFILE)

include Gasdepend
include $(DEPENDFILE)
